package com.syk.controller;

import com.github.pagehelper.PageInfo;
import com.syk.domain.User;
import com.syk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/selectAll111")
    public String selectAll111(Model model){
        List<User> list = userService.selectAll();
        model.addAttribute("list",list);
        return "index";
    }
    @RequestMapping("/selectAll")
    public String selectAll(Model model){
        List<User> list = userService.selectAll();
        model.addAttribute("list",list);
        return "index";
    }
    @RequestMapping("/pageInit")
    public String pageInit(){return "index";}
    @RequestMapping("/page")
    public String page(@RequestParam(required = true,defaultValue = "3") Integer size,
                    @RequestParam(required = true,defaultValue = "1") Integer pageNum, Model model){
        PageInfo<User> userPageInfo = userService.selectPage(pageNum, size);
        List<User> list = userPageInfo.getList();
        model.addAttribute("list",list);
        return "index";
    }
}
